package com.orangelife.mobile.surrounding.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.curry.orangelife.mobile.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.orangelife.mobile.surrounding.entity.MerchantTypeEntity;
import com.orangelife.mobile.util.BaseViewHolder;
import com.thirdsdk.qiniu.QiniuHelper;

import java.util.List;

/**
 * 商户类型列表
 * date 2015/11/13
 *
 * @author 绯若虚无
 * @since v3.4
 */
public class MerchantTypeAdapter extends BaseAdapter {

    private Context mContext;
    private List<MerchantTypeEntity> list;
    private int type;


    public MerchantTypeAdapter(Context context, List<MerchantTypeEntity> list) {
        this.mContext = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_features, null);
            holder.tv = BaseViewHolder.get(convertView, R.id.text);
            holder.iv = BaseViewHolder.get(convertView, R.id.image);
            holder.ll = BaseViewHolder.get(convertView, R.id.llfeature);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MerchantTypeEntity mte = list.get(position);
        if (mte != null) {
//            ImageDownloader.getImageDownloader().download(mte.getIcon(), holder.iv,
//                    ImageDownloader.ImageSize.IMAGE_SIZE_ORIGINAL);
            ImageLoader.getInstance().displayImage(QiniuHelper.getUrlWithQiniuListLogo(mte.getIcon()), holder.iv);
            holder.tv.setText(mte.getIndustryName());
//            holder.ll.setOnClickListener(new Listener(mte.getIndustryConfigID(), position));
        }
        return convertView;
    }

    public BaseAdapter setList(List<MerchantTypeEntity> list) {
        this.list = list;
        return MerchantTypeAdapter.this;
    }

    class ViewHolder {
        TextView tv;
        ImageView iv;
        LinearLayout ll;
    }

//    class Listener implements View.OnClickListener {
//
//        String industryConfigID;
//        int position;
//
//        public Listener(String industryConfigID, int position) {
//            this.industryConfigID = industryConfigID;
//            this.position = position;
//        }
//
//        @Override
//        public void onClick(View view) {
//            switch (view.getId()) {
//                case R.id.llfeature:
//
//                    break;
//                default:
//                    break;
//            }
//        }
//    }


}
